<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\validate;

use app\admin\model\SystemManager;
use think\Db;
use think\Validate;

class SystemManagerValidate extends Validate
{

    protected $rule = [
        ['username|登录名', 'require|unique:system_manager'],
    ];

    protected $scene = [
        'add' => ['username'],
        'edit' => ['username'=>'require|checkUserName'],
    ];

    public function checkUserName($value, $rule, $data){
        return Db::table(SystemManager::$tableName)
            ->where('username like :username AND id !=:id')
            ->bind(['username'=>$value,'id'=>[$data['id'], \PDO::PARAM_INT]])->count() < 1;
    }


}